package practise.leetcode.q12;

public class Solution {
    private String[] romans = new String[] {
        "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"
    };

    private int[] nums = new int[] {
            1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1
    };


    public String intToRoman(int num) {
        if (num < 1 || num > 3999) {
            return "";
        }

        StringBuilder sb = new StringBuilder();

        int startIdx = 0;
        while (num > 0) {
            for (int i = startIdx; i < nums.length; i++) {
                int n = nums[i];
                if (num >= n) {
                    sb.append(romans[i]);
                    num -= n;
                    break;
                }
                else {
                    startIdx++;
                }
            }
        }

        return sb.toString();
    }
}
